package com.ymatou.iapi.payment.testcase.old;
import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.payment.parameter.*;
import com.ymatou.iapi.payment.service.*;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.PaymentProxyCallService;
import com.ymttest.database.model.PPPayment;
/**
*检查是否可以退款接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CheckRefundable{
	private static CheckRefundableBean checkrefundableBean;
	private static CheckRefundableCall checkrefundableCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检查是否可以退款接口");
	}

	@Before
	public void caseUp() {
		checkrefundableBean=new CheckRefundableBean();
		checkrefundableCall=new CheckRefundableCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkrefundableCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckRefundable_001() {
		Logger.start(true,"输入可以退款TradeNos检查是否可以退款成功");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			List<String> TradeNos=new ArrayList<String>();
			TradeNos.add(aqb.getOrderId());
			checkrefundableBean.setTradeNos(TradeNos);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();
			Logger.verifyEquals("0", checkrefundableCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("true", checkrefundableCall.getString("IsSuccess"), "验证IsSuccess");
			ArrayList<Detail> list = checkrefundableCall.getDetails();
			if(list.size()==1){
				Detail d=list.get(0);
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getPayAmount().toString()), "验证PayAmount");
				Logger.verifyEquals(aqb.getCurrency(), d.getCurrencyType(), "验证CurrencyType");
				PPPayment pp = PaymentProxyCallService.getPPayment(aqb);
				Logger.verifyEquals(pp.getPaymentId(), d.getPaymentId(), "验证PaymentId");
				Logger.verifyEquals(true, d.getIsRefundable(), "验证IsRefundable");
				Logger.verifyEquals(pp.getInstitutionPaymentId(), d.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(aqb.getPayType(), d.getPayType(), "验证PayType");
				Logger.verifyEquals(new Double( aqb.getPayPrice()), new Double(d.getRefundableAmt().toString()), "验证RefundableAmt");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CheckRefundable_002() {
		Logger.start(true,"不输入TradeNos审核退款失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			PaymentProxyCallService.submitRefund(aqb);
			List<String> TradeNos=new ArrayList<String>();
			TradeNos.add(aqb.getOrderId());
//			checkrefundableBean.setTradeNos(TradeNos);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();			
			Logger.verifyEquals("1000", checkrefundableCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("参数异常|TradeNos and TradeDetails cannot be empty.", checkrefundableCall.getString("ErrorMessage"), "验证ErrorMessage");
			Logger.verifyEquals("false", checkrefundableCall.getString("IsSuccess"), "验证IsSuccess");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CheckRefundable_003() {
		Logger.start(true,"输入不可以退款TradeNos检查是否可以退款成功");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			PaymentProxyCallService.submitRefund(aqb);
			List<String> TradeNos=new ArrayList<String>();
			TradeNos.add("-1");
			checkrefundableBean.setTradeNos(TradeNos);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();				
			Logger.verifyEquals(0, checkrefundableCall.getDetails().size(), "判断Detail为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckRefundable_004() {
		Logger.start(true,"输入可以退款TradeDetails检查是否可以退款成功");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			List<TradeDetail> tradeDetails=new ArrayList<TradeDetail>();
			TradeDetail tradeDetail=new TradeDetail();
			tradeDetail.setRefundAmt(aqb.getPayPrice());
			tradeDetail.setTradeNo(aqb.getOrderId());
			tradeDetails.add(tradeDetail);
			checkrefundableBean.setTradeDetails(tradeDetails);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();
			ArrayList<Detail> list = checkrefundableCall.getDetails();
			if(list.size()==1){
				Detail d=list.get(0);
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getPayAmount().toString()), "验证PayAmount");
				Logger.verifyEquals(aqb.getCurrency(), d.getCurrencyType(), "验证CurrencyType");
				PPPayment pp = PaymentProxyCallService.getPPayment(aqb);
				Logger.verifyEquals(pp.getPaymentId(), d.getPaymentId(), "验证PaymentId");
				Logger.verifyEquals(true, d.getIsRefundable(), "验证IsRefundable");
				Logger.verifyEquals(pp.getInstitutionPaymentId(), d.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(aqb.getPayType(), d.getPayType(), "验证PayType");
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getRefundableAmt().toString()), "验证RefundableAmt");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckRefundable_005() {
		Logger.start(true,"输入小于可退金额的退款金额,可以退款");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			List<TradeDetail> tradeDetails=new ArrayList<TradeDetail>();
			TradeDetail tradeDetail=new TradeDetail();
			tradeDetail.setRefundAmt("1");
			tradeDetail.setTradeNo(aqb.getOrderId());
			tradeDetails.add(tradeDetail);
			checkrefundableBean.setTradeDetails(tradeDetails);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();			
			Logger.verifyEquals("0", checkrefundableCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("true", checkrefundableCall.getString("IsSuccess"), "验证IsSuccess");
			ArrayList<Detail> list = checkrefundableCall.getDetails();
			if(list.size()==1){
				Detail d=list.get(0);
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getPayAmount().toString()), "验证PayAmount");
				Logger.verifyEquals(aqb.getCurrency(), d.getCurrencyType(), "验证CurrencyType");
				PPPayment pp = PaymentProxyCallService.getPPayment(aqb);
				Logger.verifyEquals(pp.getPaymentId(), d.getPaymentId(), "验证PaymentId");
				Logger.verifyEquals(true, d.getIsRefundable(), "验证IsRefundable");
				Logger.verifyEquals(pp.getInstitutionPaymentId(), d.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(aqb.getPayType(), d.getPayType(), "验证PayType");
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getRefundableAmt().toString()), "验证RefundableAmt");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckRefundable_006() {
		Logger.start(true,"输入超出可退金额的退款金额,不可退款");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			List<TradeDetail> tradeDetails=new ArrayList<TradeDetail>();
			TradeDetail tradeDetail=new TradeDetail();
			tradeDetail.setRefundAmt(String.valueOf(new Double(aqb.getPayPrice())+1));
			tradeDetail.setTradeNo(aqb.getOrderId());
			tradeDetails.add(tradeDetail);
			checkrefundableBean.setTradeDetails(tradeDetails);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();			
			Logger.verifyEquals("0", checkrefundableCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("true", checkrefundableCall.getString("IsSuccess"), "验证IsSuccess");
			ArrayList<Detail> list = checkrefundableCall.getDetails();
			if(list.size()==1){
				Detail d=list.get(0);
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getPayAmount().toString()), "验证PayAmount");
				Logger.verifyEquals(aqb.getCurrency(), d.getCurrencyType(), "验证CurrencyType");
				PPPayment pp = PaymentProxyCallService.getPPayment(aqb);
				Logger.verifyEquals(pp.getPaymentId(), d.getPaymentId(), "验证PaymentId");
				Logger.verifyEquals(false, d.getIsRefundable(), "验证IsRefundable");
				Logger.verifyEquals(pp.getInstitutionPaymentId(), d.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(aqb.getPayType(), d.getPayType(), "验证PayType");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckRefundable_007() {
		Logger.start(true,"全部提交退款后查询,不可退款");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			SubmitRefundBean srb = PaymentProxyCallService.submitRefund(aqb);
			List<TradeDetail> tradeDetails=new ArrayList<TradeDetail>();
			TradeDetail tradeDetail=new TradeDetail();
			tradeDetail.setRefundAmt(String.valueOf(new Double(aqb.getPayPrice())));
			tradeDetail.setTradeNo(aqb.getOrderId());
			tradeDetails.add(tradeDetail);
			checkrefundableBean.setTradeDetails(tradeDetails);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();			
			Logger.verifyEquals("0", checkrefundableCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("true", checkrefundableCall.getString("IsSuccess"), "验证IsSuccess");
			ArrayList<Detail> list = checkrefundableCall.getDetails();
			if(list.size()==1){
				Detail d=list.get(0);
				Logger.verifyEquals(srb.getTradeDetails().get(0).getTradeNo(), d.getTradeNo(), "验证TradeNo");
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getPayAmount().toString()), "验证PayAmount");
				Logger.verifyEquals(aqb.getCurrency(), d.getCurrencyType(), "验证CurrencyType");
				PPPayment pp = PaymentProxyCallService.getPPayment(aqb);
				Logger.verifyEquals(pp.getPaymentId(), d.getPaymentId(), "验证PaymentId");
				Logger.verifyEquals(false, d.getIsRefundable(), "验证IsRefundable");
				Logger.verifyEquals(pp.getInstitutionPaymentId(), d.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(aqb.getPayType(), d.getPayType(), "验证PayType");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckRefundable_008() {
		Logger.start(true,"部分提交退款后查询,可以退款");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			//这里需要改成新的提交
			AcquireRefundBean ar = PaymentProxyCallService.AcquireRefund(aqb, "1");
			List<TradeDetail> tradeDetails=new ArrayList<TradeDetail>();
			TradeDetail tradeDetail=new TradeDetail();
			tradeDetail.setRefundAmt("1");
			tradeDetail.setTradeNo(aqb.getOrderId());
			tradeDetails.add(tradeDetail);
			checkrefundableBean.setTradeDetails(tradeDetails);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();			
			Logger.verifyEquals("0", checkrefundableCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("true", checkrefundableCall.getString("IsSuccess"), "验证IsSuccess");
			ArrayList<Detail> list = checkrefundableCall.getDetails();
			if(list.size()==1){
				Detail d=list.get(0);
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getPayAmount().toString()), "验证PayAmount");
				Logger.verifyEquals(aqb.getCurrency(), d.getCurrencyType(), "验证CurrencyType");
				PPPayment pp = PaymentProxyCallService.getPPayment(aqb);
				Logger.verifyEquals(pp.getPaymentId(), d.getPaymentId(), "验证PaymentId");
				Logger.verifyEquals(true, d.getIsRefundable(), "验证IsRefundable");
				Logger.verifyEquals(pp.getInstitutionPaymentId(), d.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(aqb.getPayType(), d.getPayType(), "验证PayType");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckRefundable_009() {
		Logger.start(true,"applepay输入可以退款TradeNos检查是否可以退款成功");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("60");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			List<String> TradeNos=new ArrayList<String>();
			TradeNos.add(aqb.getOrderId());
			checkrefundableBean.setTradeNos(TradeNos);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();
			Logger.verifyEquals("0", checkrefundableCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("true", checkrefundableCall.getString("IsSuccess"), "验证IsSuccess");
			ArrayList<Detail> list = checkrefundableCall.getDetails();
			if(list.size()==1){
				Detail d=list.get(0);
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getPayAmount().toString()), "验证PayAmount");
				Logger.verifyEquals(aqb.getCurrency(), d.getCurrencyType(), "验证CurrencyType");
				PPPayment pp = PaymentProxyCallService.getPPayment(aqb);
				Logger.verifyEquals(pp.getPaymentId(), d.getPaymentId(), "验证PaymentId");
				Logger.verifyEquals(true, d.getIsRefundable(), "验证IsRefundable");
				Logger.verifyEquals(pp.getInstitutionPaymentId(), d.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(aqb.getPayType(), d.getPayType(), "验证PayType");
				Logger.verifyEquals(new Double( aqb.getPayPrice()), new Double(d.getRefundableAmt().toString()), "验证RefundableAmt");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckRefundable_010() {
		Logger.start(true,"baofu输入可以退款TradeNos检查是否可以退款成功");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("70");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			List<String> TradeNos=new ArrayList<String>();
			TradeNos.add(aqb.getOrderId());
			checkrefundableBean.setTradeNos(TradeNos);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();
			Logger.verifyEquals("0", checkrefundableCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("true", checkrefundableCall.getString("IsSuccess"), "验证IsSuccess");
			ArrayList<Detail> list = checkrefundableCall.getDetails();
			if(list.size()==1){
				Detail d=list.get(0);
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getPayAmount().toString()), "验证PayAmount");
				Logger.verifyEquals(aqb.getCurrency(), d.getCurrencyType(), "验证CurrencyType");
				PPPayment pp = PaymentProxyCallService.getPPayment(aqb);
				Logger.verifyEquals(pp.getPaymentId(), d.getPaymentId(), "验证PaymentId");
				Logger.verifyEquals(true, d.getIsRefundable(), "验证IsRefundable");
				Logger.verifyEquals(pp.getInstitutionPaymentId(), d.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(aqb.getPayType(), d.getPayType(), "验证PayType");
				Logger.verifyEquals(new Double( aqb.getPayPrice()), new Double(d.getRefundableAmt().toString()), "验证RefundableAmt");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckRefundable_011() {
		Logger.start(true,"花呗输入可以退款TradeNos检查是否可以退款成功");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("9");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			List<String> TradeNos=new ArrayList<String>();
			TradeNos.add(aqb.getOrderId());
			checkrefundableBean.setTradeNos(TradeNos);
			checkrefundableCall.setData(checkrefundableBean);
			checkrefundableCall.callService();
			Logger.verifyEquals("0", checkrefundableCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("true", checkrefundableCall.getString("IsSuccess"), "验证IsSuccess");
			ArrayList<Detail> list = checkrefundableCall.getDetails();
			if(list.size()==1){
				Detail d=list.get(0);
				Logger.verifyEquals(new Double(aqb.getPayPrice()), new Double(d.getPayAmount().toString()), "验证PayAmount");
				Logger.verifyEquals(aqb.getCurrency(), d.getCurrencyType(), "验证CurrencyType");
				PPPayment pp = PaymentProxyCallService.getPPayment(aqb);
				Logger.verifyEquals(pp.getPaymentId(), d.getPaymentId(), "验证PaymentId");
				Logger.verifyEquals(true, d.getIsRefundable(), "验证IsRefundable");
				Logger.verifyEquals(pp.getInstitutionPaymentId(), d.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(aqb.getPayType(), d.getPayType(), "验证PayType");
				Logger.verifyEquals(new Double( aqb.getPayPrice()), new Double(d.getRefundableAmt().toString()), "验证RefundableAmt");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}